home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 5.1 KB | 169 lines | [TEXT/GEOL] |
- Item forwarded by BOSURGI1 to RICHARDSON7
-
- Item 3800615 25-June-90 23:47PDT
-
- From: AUST0334 AUDev - CRIA, Canberra, ACT,IDV
-
- To: MACAPP.TECH$ MacApp Technical
-
- Sub: Styled Lengths
-
-
- In MacApp 2.0 final, TTEView.CalcRealWidth is only called if the TextEdit is a
- non-styled type.
-
- It would be better if it was always called, but returned a default width if it
- was styled. This would then make it simpler for the rest of us to override the
- method to cope with our own peculiar circumstances.
-
- Here are the changes I have made to TTEView.CalcRealWidth to facilitate this.
- (I have not included here the changes to the calling tests.)
- (Note: I have also moved the addition of two insertion point widths into here,
- from SynchView)
-
-
- {• CalcRealWidth := aWidth;•}
- { DBL - Add the space required for I beams here, instead of in SynchView }
- CalcRealWidth := aWidth + kInsertionBarWidth * 2;
- end
- end
- {• else if qDebug then•}
- {• ProgramBreak('IN TTEView.CalcRealWidth: called for a styled TE Record');•}
- { DBL - I am modifying this routine to return the usual default, instead of
- the MacApp technique of }
- { testing for fStyleType at higher levels }
- else
- CalcRealWidth := fSize.h - fInset.left - fInset.right;
- end;
-
-
- In TTEView.CalcRealWidth, there is the following comment:-
-
- { !!! it would be nice to compute this for styled TE but TEGetPoint only
- returns the bottom}
- { left of the character box so it can't be used to find the width including
- last character}
- { in a line. And since some characters can change width based on context we
- can't just}
- { measure the last character and add it in. Maybe we can makeup an formula
- based on}
- { style runs or something eventually.}
-
-
-
- Naturally, our application uses styled TE's, and so here is the formula based
- on style runs which we have had to develop.
- {==================================================================}
- { TFormTEView.CalcRealWidth }
- {==================================================================}
- function TFormTEView.CalcRealWidth: LONGINT;
- { go through all lines of text, and calculate the longest , in points}
-
- {==================================================================}
- function RunWidth (startChar: INTEGER;
- length: INTEGER;
- hTE: TEHandle): INTEGER;
- var
- aTextStyle: TextStyle;
- lineHeight: INTEGER;
- fontAscent: INTEGER;
- theFontinfo: FontInfo;
- begin
- TEGetStyle(startChar, aTextStyle, lineHeight, fontAscent, hTE);
- SetPortTextStyle(aTextStyle);
- RunWidth := TextWidth(QDPtr(hTE^^.hText^), startChar, length);
- end;
-
- {==================================================================}
- function NextStyleAfter (posn: INTEGER;
- hTE: TEHandle): INTEGER;
- var
- theStyleHandle: TEStyleHandle;
- currentRun: INTEGER;
- begin
- NextStyleAfter := hTE^^.teLength + 1; { end of text as default }
- theStyleHandle := GetStylHandle(fHTE);
- with theStyleHandle^^ do
- begin
- for currentRun := nRuns - 1 downto 0 do
- if runs[currentRun].startChar > posn then
- NextStyleAfter := runs[currentRun].startChar;
- end;
- end;
-
- {==================================================================}
- function LineLength (startChar: INTEGER; { starting character in this line
- }
- nextLineStart: INTEGER; { starting character in next line }
- hTE: TEHandle): INTEGER;
- var
- runStart: INTEGER;
- nextRunStart: INTEGER;
- runLength: INTEGER;
- lineTotal: INTEGER;
- begin
- lineTotal := 0;
- runStart := startChar;
- repeat
- nextRunStart := min(nextLineStart, NextStyleAfter(runStart, hTE));
- runLength := nextRunStart - runStart;
- if runLength > 0 then
- lineTotal := lineTotal + RunWidth(runStart, runLength, hTE);
- runStart := nextRunStart;
- until nextRunStart >= nextLineStart;
- LineLength := lineTotal;
- end;
-
- {==================================================================}
- const
- kInsertionBarWidth = 1; { We all _KNOW_ an insertion bar is one}
- {pixel wide right?}
- var
- textWasLocked: BOOLEAN;
- TEWasLocked: BOOLEAN;
- lineWidth: INTEGER;
- currentLine: INTEGER;
- oldPort: GrafPtr;
- begin
- with fHTE^^ do
- begin
- textWasLocked := IsHandleLocked(hText);
- HLock(hText); {??? Better to LockHandleHigh? }
- TEWasLocked := IsHandleLocked(fHTE);
- HLock(HANDLE(fHTE));{??? Better to LockHandleHigh? }
-
- lineWidth := 0;
- maxCharWidth := 0; { will be updated during linewidth calcs }
- if teLength > 0 then
- begin
- GetPort(oldPort);
- SetPort(gWorkPort);
-
- Assert(nLines > 0, 'TFormTEView . CalcRealWidth - nLines = 0');
- for currentLine := 0 to nLines - 1 do
- lineWidth := MAX(lineWidth, LineLength(lineStarts[currentLine],
- lineStarts[currentLine + 1], fHTE));
-
- lineWidth := lineWidth + kInsertionBarWidth * 2;
-
-
- SetPort(oldPort);
- if not textWasLocked then
- HUnlock(hText);
- if not TEWasLocked then
- HUnlock(HANDLE(fHTE));
- end;
- end;
- end;
-
-
- There. Wasn't so bad after all, was it?
-
- Don Lawn
- Techway Solutions
- Canberra, Australia
- AppleLink: AUST0334
-
-
-
-